
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>编辑投票信息</title>
<link rel="stylesheet"
	href="https://fonts.googleapis.com/css?family=Roboto:400,700" />
<link rel="stylesheet" href="../css/fontawesome.min.css" />
<link rel="stylesheet" href="../jquery-ui-datepicker/jquery-ui.min.css"
	type="text/css" />
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/templatemo-style.css">
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery-1.8.3.min.js"></script>
<script src="../js/jquery-3.5.1.js"></script>
<script src="../js/bootstrap.js"></script>
<script>
	$(function() {
		$("#but").click(function() {
			window.location.href = "add-option.html";
			return false;

		});
	});
</script>
</head>
<script src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
		let re2 = new RegExp("\s?" + "item_id" + "=([^;]+)(;|$)")
		var item_id=document.cookie.match(re2)[1];
		var arry2;
		function voteOption() {
			 $.ajax({
	                url: "http://localhost:8080/voting-system/getItemOption",
	                type: "post",
	                success:function (data) {
	                	arry2=data;
	                    var tbhtml = "<table class=\"table table-hover tm-table-small tm-product-table\"><thead><tr><th scope=\"col\">&nbsp;</th><th scope=\"col\">序号</th><th scope=\"col\">投票选项</th><th scope=\"col\">&nbsp;</th></tr></thead><tbody>";
	                    for(var i = 0;i<data.length;i++){
	                    	var j=i+1;
	                    	tbhtml += "<tr><th scope=\"row\"><input type=\"radio\" name=\"option\" value=\""+data[i].option_id+"\"/></th><td class=\"tm-product-name\">"+j+"</td><td>"+data[i].option_text+"</td></tr>";
	                    }
	                        tbhtml += "</tbody></table>";
	                	$("#itemOption").html(tbhtml);
	                },
	                dataType: "json",
	                data:{item_id:item_id}
	            });
           
        }
		function deleteOption(){
			var value="";
			var radio=document.getElementsByName("option");
			for(var i=0;i<radio.length;i++){
				if(radio[i].checked==true){
					value=radio[i].value;
					break;
				}
			}
			if(value==""){
				alert("请选择选项")
			}
			$.ajax({
				url : "http://localhost:8080/voting-system/deleteItemOption",
				type : "post",
				success : function(data) {
					if(data.delectItem==false){
						alert("删除失败！")
					}else{
						//window.location.href='edit-product.html'
						alert("删除成功！")
					}
				},
				dataType : "json",
				data:{option_id:value}
			});
		}
</script>
<body onload="voteOption()">
	<nav class="navbar navbar-expand-xl">
		<div class="container h-100">

			<button class="navbar-toggler ml-auto mr-0" type="button"
				data-toggle="collapse" data-target="#navbarSupportedContent"
				aria-controls="navbarSupportedContent" aria-expanded="false"
				aria-label="Toggle navigation">
				<i class="fas fa-bars tm-nav-icon"></i>
			</button>

			<div class="collapse navbar-collapse" id="navbarSupportedContent">
				<ul class="navbar-nav mx-auto h-100">
					<li class="nav-item"><a class="nav-link" href="result.jsp">
							<i class="fas fa-tachometer-alt"></i> 投票结果 <span class="sr-only">(current)</span>
					</a></li>
					<li class="nav-item dropdown"><a
						class="nav-link dropdown-toggle" href="update.html"> <i
							class="far fa-file-alt"></i> <span>用户管理 </span>
					</a></li>
					<li class="nav-item"><a class="nav-link active"
						href="manage.html"> <i class="fas fa-shopping-cart"></i> 投票管理
					</a></li>

					<li class="nav-item"><a class="nav-link" href="center.html">
							<i class="far fa-user"></i> 个人中心
					</a></li>

				</ul>
				<ul class="navbar-nav">
					<li class="nav-item"><a class="nav-link d-block"
						href="../login.html"> <b>退出登录</b>
					</a></li>
				</ul>
			</div>
		</div>
	</nav>
	<div class="container tm-mt-big tm-mb-big">
		<div class="row">
			<div class="col-xl-9 col-lg-10 col-md-12 col-sm-12 mx-auto">
				<div class="tm-bg-primary-dark tm-block tm-block-h-auto">
					<div class="row">
						<div class="col-12">
							<h2 align="center">
								<font size="+1" color="white">编辑投票选项</font>
							</h2>
						</div>
					</div>
					<div class="row tm-edit-product-row">
						<div class="col-xl-6 col-lg-6 col-md-12">
							<form action="" method="post" class="tm-edit-product-form">
								<div style="position: relative; left: 190px;"
									class="tm-product-table-container" id="itemOption">
									<!--  <table
										class="table table-hover tm-table-small tm-product-table">
										<thead>
											<tr>
												<th scope="col">&nbsp;</th>
												<th scope="col">选项</th>

												<th scope="col">选项内容</th>

												<th scope="col">&nbsp;</th>
											</tr>
										</thead>
										<tbody>
											<tr>
												<th scope="row"><input type="checkbox" /></th>
												<td class="tm-product-name">1</td>
												<td>1,450</td>

												<td><a href="#" class="tm-product-delete-link"> <i
														class="far fa-trash-alt tm-product-delete-icon"></i>
												</a></td>
											</tr>
											<tr>
												<th scope="row"><input type="checkbox" /></th>
												<td class="tm-product-name">2</td>
												<td>1,250</td>

												<td><a href="#" class="tm-product-delete-link"> <i
														class="far fa-trash-alt tm-product-delete-icon"></i>
												</a></td>
											</tr>
											<tr>
												<th scope="row"><input type="checkbox" /></th>
												<td class="tm-product-name">3</td>
												<td>1,100</td>

												<td><a href="#" class="tm-product-delete-link"> <i
														class="far fa-trash-alt tm-product-delete-icon"></i>
												</a></td>
											</tr>
											<tr>
												<th scope="row"><input type="checkbox" /></th>
												<td class="tm-product-name">4</td>
												<td>1,400</td>

												<td><a href="#" class="tm-product-delete-link"> <i
														class="far fa-trash-alt tm-product-delete-icon"></i>
												</a></td>
											</tr>
											<tr>
												<th scope="row"><input type="checkbox" /></th>
												<td class="tm-product-name">5</td>
												<td>1,800</td>

												<td><a href="#" class="tm-product-delete-link"> <i
														class="far fa-trash-alt tm-product-delete-icon"></i>
												</a></td>
											</tr>

										</tbody>
									</table>-->

								</div>
								<br>
						</div>
						<div class="col-12">
							<button id="but" type="submit"
								class="btn btn-primary btn-block text-uppercase">添加投票选项</button>
							<button type="submit" onclick="deleteOption()"
								class="btn btn-primary btn-block text-uppercase">删除所选选项</button>
						</div>
						</form>
						
					</div>
				</div>
			</div>
		</div>
	</div>



</body>
</html>
